<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/5/9
  Time: 15:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<script>

    //所以我们跳转到页面之前，需要进行查询操作，即
    $(function () {
        chaxunById();
    });

    function chaxunById() {
        let navId = localStorage.getItem("navId");//将得到的ID去数据库里面查询，并把查询出来的值赋值给当前页面对应的数据
        $.ajax({
            url: '/navFindById',//这里应该是更具ID进行查询
            data: {id: navId},
            type: 'get',
            dataType: 'json',
            success: function (data) {
                //将返回过来的值赋值
                $("#id").val(data[0].id);
                $("#hrefa").val(data[0].href);
                $("#title").val(data[0].title);
                //更具后台传递过来的status的值判断哪一个被选中
                let status = data[0].status;
                console.log(status == 1);
                if (status == 1) {
                    $("input[name='status'][value='启用']").attr("checked", true);
                } else {
                    $("input[name='status'][value='停用']").attr("checked", true);
                }
            }
        })
    }

    function tijiao() {
        let status = $("input[name='status']:checked").val();
        status = status == "启用" ? 1 : 0;
        let data = {
                id: $("#id").val(),
                href: $("#hrefa").val(),
                title: $("#title").val(),
                status: status
            }
        ;//封装传递给后台的数据数据
        $.ajax({
            url: '/navUpdate',
            data: data,
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if (data == 1) {
                    $('#homeright').load('/back/navSelect.jsp');
                } else {
                    alert("很遗憾，操作失败");
                }
            }
        })
    }
</script>
<body>
<div>id：<input type="text" id="id" readonly></div>
<div>
    导航链接：<input type="text" name="hrefa" id="hrefa">
</div>
<div>
    导航标题：<input type="text" name="title" id="title">
</div>
<div>状态：<label><input type="radio" name="status" value="启用">启用</label>
    <label><input type="radio" name="status" value="停用">停用</label>
</div>
<div>
    <input type="button" value="修改" onclick="tijiao()">
</div>
</body>
</html>
